export function formatTimestamp(timestamp) {
    const now = Date.now();
    const diff = now - timestamp; // 时间差，单位毫秒

    const minute = 60 * 1000; // 1分钟 = 60,000毫秒
    const hour = 60 * minute; // 1小时 = 3,600,000毫秒
    const day = 24 * hour; // 1天 = 86,400,000毫秒
    const month = 30 * day; // 1个月 ≈ 2,592,000,000毫秒
    const threeMonths = 3 * month; // 3个月 ≈ 7,776,000,000毫秒

    if (diff < minute) {
        return "一分钟内更新";
    } else if (diff < hour) {
        const minutes = Math.floor(diff / minute);
        return `${minutes}分钟前更新`;
    } else if (diff < day) {
        const hours = Math.floor(diff / hour);
        return `${hours}小时前更新`;
    } else if (diff < month) {
        const days = Math.floor(diff / day);
        return `${days}天前更新`;
    } else if (diff < threeMonths) {
        const months = Math.floor(diff / month);
        return `${months}个月前更新`;
    } else {
        return null; // 超过三个月返回null
    }
}

export function gotoHome(){
	uni.showModal({
		title:"提示",
		content:"页面有误将返回首页",
		showCancel:false,
		success(res) {
			if(res.confirm){
				uni.reLaunch({
					url:'/pages/index/index'
				})
			}
		}
	})
}